//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "FdSimpleKlugeExtOUVPPEngine.h"
using namespace Cephei::QL::Experimental::Finitedifferences;
#include <gen/QL/Experimental/Processes/KlugeExtOUProcess.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Methods/Finitedifferences/Solvers/FdmSchemeDesc.h>
#include <gen/QL/PricingEngine.h>
using namespace Cephei::QL::Experimental::Processes;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Methods::Finitedifferences::Solvers;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine>& childNative, Object^ owner) : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleKlugeExtOUVPPEngine = NULL;
#endif
	_ppFdSimpleKlugeExtOUVPPEngine = &childNative;
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (QuantLib::FdSimpleKlugeExtOUVPPEngine& childNative, Object^ owner) : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleKlugeExtOUVPPEngine = NULL;
#endif
	_ppFdSimpleKlugeExtOUVPPEngine = new boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine> (&childNative);
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
    _FdSimpleKlugeExtOUVPPEngineOwner = owner;
    _PricingEngineOwner = owner;
}

Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (CFdSimpleKlugeExtOUVPPEngine^ copy) : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleKlugeExtOUVPPEngine = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFdSimpleKlugeExtOUVPPEngine = new boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine> (copy->GetShared());
        _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (PLATFORM::Type^ t) : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleKlugeExtOUVPPEngine = NULL;
#endif
	if (!t->IsSubclassOf(CFdSimpleKlugeExtOUVPPEngine::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (QuantLib::Handle<QuantLib::FdSimpleKlugeExtOUVPPEngine>& childNative, Object^ owner)  : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
	_phFdSimpleKlugeExtOUVPPEngine = &childNative;
	_ppFdSimpleKlugeExtOUVPPEngine = &static_cast<boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
    _FdSimpleKlugeExtOUVPPEngineOwner = owner;
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (QuantLib::Handle<QuantLib::FdSimpleKlugeExtOUVPPEngine> childNative)  : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
	_phFdSimpleKlugeExtOUVPPEngine = &childNative;
	_ppFdSimpleKlugeExtOUVPPEngine = &static_cast<boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::CFdSimpleKlugeExtOUVPPEngine (QuantLib::FdSimpleKlugeExtOUVPPEngine childNative)  : CPricingEngine(CFdSimpleKlugeExtOUVPPEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleKlugeExtOUVPPEngine = NULL;
#endif
	_ppFdSimpleKlugeExtOUVPPEngine = new boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine> (new QuantLib::FdSimpleKlugeExtOUVPPEngine (childNative));
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleKlugeExtOUVPPEngine));
}
#endif

Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::~CFdSimpleKlugeExtOUVPPEngine ()
{
    if (_ppFdSimpleKlugeExtOUVPPEngine != NULL)
    {
	    delete _ppFdSimpleKlugeExtOUVPPEngine;
        _ppFdSimpleKlugeExtOUVPPEngine = NULL;
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::!CFdSimpleKlugeExtOUVPPEngine ()
{
    if (_ppFdSimpleKlugeExtOUVPPEngine != NULL)
    {
	    delete _ppFdSimpleKlugeExtOUVPPEngine;
    }
}
QuantLib::FdSimpleKlugeExtOUVPPEngine& Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::GetReference ()
{
    if (_ppFdSimpleKlugeExtOUVPPEngine == NULL) throw REFNEW NativeNullException ();
	return **_ppFdSimpleKlugeExtOUVPPEngine;
}
boost::shared_ptr<QuantLib::FdSimpleKlugeExtOUVPPEngine>& Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::GetShared ()
{
    if (_ppFdSimpleKlugeExtOUVPPEngine == NULL) throw REFNEW NativeNullException ();
	return *_ppFdSimpleKlugeExtOUVPPEngine;
}
QuantLib::FdSimpleKlugeExtOUVPPEngine* Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::GetPointer ()
{
    if (_ppFdSimpleKlugeExtOUVPPEngine == NULL) throw REFNEW NativeNullException ();
	return &**_ppFdSimpleKlugeExtOUVPPEngine;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FdSimpleKlugeExtOUVPPEngine>& Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::GetHandle ()
{
	if (_phFdSimpleKlugeExtOUVPPEngine == NULL)
	{
		_phFdSimpleKlugeExtOUVPPEngine = new Handle<QuantLib::FdSimpleKlugeExtOUVPPEngine> (*_ppFdSimpleKlugeExtOUVPPEngine);
	}
	return *_phFdSimpleKlugeExtOUVPPEngine;
}
#endif
bool Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::HasNative () 
{
	return (_ppFdSimpleKlugeExtOUVPPEngine != NULL);
}

Cephei::QL::Experimental::Finitedifferences::IFdSimpleKlugeExtOUVPPEngine^ Cephei::QL::Experimental::Finitedifferences::CFdSimpleKlugeExtOUVPPEngine::Calculate::get ()
{
    try
    {
    	(*_ppFdSimpleKlugeExtOUVPPEngine)->calculate ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

